package com.aaa.controller.front;

import com.aaa.entity.Category;
import com.aaa.entity.Goods;

import com.aaa.service.front.IIdexService;
import com.aaa.service.front.ZMRICategoryService;
import com.aaa.service.front.ZMRIGoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RequestMapping("/front")
@Controller
public class IndexController {
    @Resource
    private IIdexService iIdexService;
    @Resource
    private ZMRICategoryService categoryService;

    @Resource
    private ZMRIGoodsService zmrGoodsService;
    //首页
    @RequestMapping("/index")
    public String index(Model model,String goodsId,Integer categoryId){
        List<Goods> goodsList=iIdexService.list();
        model.addAttribute("goodsList",goodsList);

        List<Category> categoryList = iIdexService.findAllById(categoryId);
        model.addAttribute("categoryList",categoryList);

        List<Goods> GoodsId = iIdexService.findByGoodsId(goodsId);
        model.addAttribute("GoodsId",GoodsId);







        Map<String, Object> goodsMap = iIdexService.queryByGoods(goodsId);
        model.addAttribute("goodsMap",goodsMap);

        Map<String, Object> goodsMapF = iIdexService.queryByGoodsF(goodsId);
        model.addAttribute("goodsMapF",goodsMapF);

        Map<String, Object> goodsMapJ = iIdexService.queryByGoodsJ(goodsId);
        model.addAttribute("goodsMapJ",goodsMapJ);
        return "front/index";
    }

    @RequestMapping("/queryByGoods")
    public String queryByGoods(Model model,String goodsId){
        List<Goods> GoodsIdList = zmrGoodsService.findByGoodsId(goodsId);
        model.addAttribute("GoodsIdList",GoodsIdList);

        Map<String, Object> goodsMap = iIdexService.queryByGoods(goodsId);
        model.addAttribute("goodsMap",goodsMap);

        return "front/shop-details-variable";
    }

    @RequestMapping("/queryByGoodsF")
    public String queryByGoodsF(Model model,String goodsId){
        List<Goods> GoodsIdList = zmrGoodsService.findByGoodsId(goodsId);
        model.addAttribute("GoodsIdList",GoodsIdList);

        Map<String, Object> goodsMapF = iIdexService.queryByGoodsF(goodsId);
        model.addAttribute("goodsMapF",goodsMapF);
        return "front/shop-details-variable";
    }

    @RequestMapping("/queryByGoodsJ")
    public String queryByGoodsJ(Model model,String goodsId){
        List<Goods> GoodsIdList = zmrGoodsService.findByGoodsId(goodsId);
        model.addAttribute("GoodsIdList",GoodsIdList);


        Map<String, Object> goodsMapJ = iIdexService.queryByGoodsJ(goodsId);
        model.addAttribute("goodsMapJ",goodsMapJ);
        return "front/shop-details-variable";
    }

}
